package com.psy.counseling.service.impl;

import com.psy.counseling.entity.Article;
import com.psy.counseling.mapper.ArticleMapper;
import com.psy.counseling.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.psy.counseling.utils.ImportArticleUtil;
import com.psy.counseling.utils.ImportQuestionUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 梁学儒
 * @since 2022-05-31
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Transactional
    @Override
    public ArrayList<Integer> importArticles(MultipartFile multipartFile) throws IOException {
        FileInputStream fileInputStream = (FileInputStream) multipartFile.getInputStream();
        ImportArticleUtil importArticle = new ImportArticleUtil(fileInputStream);
        this.saveBatch(importArticle.getImportSuccess());
        return importArticle.getImportError();
    }
}
